#!/usr/bin/bash
#
# Check a data file is valid according to its sha256sum file
#

function fatal
{
    echo "$*" >&2
    exit 1
}

data_file=${1:-"docker-compose-linux-x86_64"}
sha256sum_file=${2:-"${data_file}.sha256sum"}

[[ ! -f "$data_file" ]] && fatal "Oops, file '$data_file' not found."
[[ ! -f "$sha256sum_file" ]] && fatal "Oops, file '$sha256sum_file' not found."

sr=$(cat "$sha256sum_file"  | awk '{print $1}')
sl=$(sha256sum "$data_file" | awk '{print $1}')
[[ "$sr" != "$sl" ]] && fatal "Oops, file '$data_file' is invalid!"

echo "OKAY - file '$data_file' is valid."
exit 0
